import 'package:flutter/material.dart';
import 'package:flutter_study/pages/chapter2/new_route.dart';
import 'package:flutter_study/pages/chapter2/tip_route.dart';
import 'package:logger/logger.dart';

class Chapter2Page extends StatelessWidget {
  Chapter2Page({Key? key}) : super(key: key);
  final logger = Logger(printer: PrettyPrinter());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("第二章 第一个Flutter应用"),
        leading: IconButton(
          icon: const Icon(Icons.home),
          onPressed: () => Navigator.of(context).pushNamed("/"),
        ),
      ),
      body: SingleChildScrollView(
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("State生命周期"),
                onPressed: () =>
                    Navigator.of(context).pushNamed("/chapter2/counter"),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("Cupertino Demo"),
                onPressed: () =>
                    Navigator.of(context).pushNamed("/chapter2/cupertino"),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("通过Context获取状态"),
                onPressed: () =>
                    Navigator.of(context).pushNamed("/chapter2/get/state"),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("状态管理"),
                onPressed: () =>
                    Navigator.of(context).pushNamed("/chapter2/tap/box"),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("新的路由"),
                onPressed: () => Navigator.push(context,
                    MaterialPageRoute(builder: (context) => const NewRoute())),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("新的路由传值"),
                onPressed: () async {
                  var result = await Navigator.of(context).push<String>(
                    MaterialPageRoute(
                      builder: (context) => const TipRoute(
                        text: "我是提示xxxx",
                      ),
                    ),
                  );
                  logger.i("result : $result");
                },
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("新的命名路由传值"),
                onPressed: () async {
                  var result = await Navigator.of(context)
                      .pushNamed("/chapter2/tip/route", arguments: "命名路由传值");
                  logger.i("result : $result");
                },
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("包管理"),
                onPressed: () =>
                    Navigator.of(context).pushNamed("/chapter2/random/words"),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("资源管理"),
                onPressed: () =>
                    Navigator.of(context).pushNamed("/chapter2/assets/route"),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                child: const Text("日志与断点"),
                onPressed: () =>
                    Navigator.of(context).pushNamed("/chapter2/debugger"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
